package News.service;

import com.alibaba.fastjson.JSONArray;

public class UserServer {

    NewsServer cr=new NewsServer();

    public int selectJSONCount(String username, String pwd){
        String sql="select count(1) from WSQ.user where userName='"+username+"' and pwd='"+pwd+"' and isdelete=1";
        int i=cr.selectJSONCount(sql);
        return i;
    }

    public Integer selectUser(String username,String pwd){
        String sql="select count(*) from WSQ.user where userName=? and pwd=? and isdelete=1";
        Object []o={username,pwd};//tj
        Integer i= cr.select(sql,o);
        return i;
    }

    public Integer selectUserIsControl(String username,String pwd){
        String sql="select isControl from WSQ.user where userName=? and pwd=? and isdelete=1";
        Object []o={username,pwd};//tj
        Integer i= cr.select(sql,o);
        return i;
    }

    public Integer selectUserName(String username){
        String sql="select count(*) from WSQ.user where userName=? and isdelete=1";
        Object []o={username};
        Integer i= cr.select(sql,o);
        return i;
    }

    public int Register(String username,String pwd,int isControl){
        Object []o={username,pwd,isControl};
        String sql="insert into WSQ.user(username,pwd,isControl) values(?,?,?)";
        int i=cr.update(sql,o);
        return i;
    }
    public int Register(String username,String pwd){
        Object []o={username,pwd};
        String sql="insert into WSQ.user(username,pwd) values(?,?)";
        int i=cr.update(sql,o);
        return i;
    }

    public int add(String news){
        String sql="insert into WSQ.news(newInfo) values(?)";
        String []o={news};
        int i=cr.update(sql,o);
        return i;
    }

    public int drop(int index){
        String sql="update WSQ.news set isdelete=0 where newId=?";
        Object []o={index};
        int i=cr.update(sql,o);
        return i;
    }

    public static void main(String[] args) {
        UserServer l =new UserServer();
        Integer i=l.selectUser("wsqsSA","wsq");
        System.out.println(i);
    }

//    public static void main(String[] args) {
//        Login l =new Login();
//        List<News> list=l.show();
//        for(News n:list){
//            System.out.println(n.getNewInfo());
//        }
//    }

//    public static void main(String[] args) {
//        Login l =new Login();
//        int i=l.add("知名艺人死亡！");
//        System.out.println(i);
//    }

//    public static void main(String[] args) {
//        Login l =new Login();
//        int i=l.Register("sss","sss",1);
//        System.out.println(i);
//    }
}
